{extend name="public:head"}
{block name="main"}

<form class="layui-form" style="margin: 20px">
    <div class="demoTable">
        条件搜索：

        <div class="layui-input-inline">
            <input name="time" type="text" class="layui-input" id="date" placeholder="输入时间范围">
        </div>

        <div class="layui-inline">
            <button class="layui-btn" lay-filter="submit" lay-submit>搜索</button>
            <button class="layui-btn layui-btn-primary"  lay-filter="submit" lay-submit>重置</button>
        </div>

    </div>
</form>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="getType">
    {{#  if(d.type == 'f'){ }} <a class="layui-btn layui-btn-xs layui-btn-normal">分期 </a> {{#  } }}
    {{#  if(d.type == 'd'){ }} <a class="layui-btn layui-btn-xs">单期 </a> {{#  } }}
</script>

<script type="text/html" id="getFirst">
    {{#  if(d.first == '1'){ }}  <a class="layui-btn layui-btn-xs layui-btn-normal">首次注册 </a>{{#  } }}
</script>

<table  class="layui-hide" id="all" lay-filter="all" lay-data="{id: 'sousuo'}"></table>



<script>
    layui.use(['table','layer','form','laydate'], function(){
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        table.render({
            elem: '#all'
            ,url:'/sign/Registered/getHasRegistered'
            ,toolbar: '#toolbarDemo'
            ,method:"get"
            ,limits: [10, 20, 40, 80, 160, 320, 640, 1280]
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'from', title:'推广方', width: 80}
                ,{field:'phone', title:'注册手机', width: 123}
                ,{field:'first', title:'注册状态',toolbar: '#getFirst',width: 90}
                ,{field:'type', title:'贷款类型', toolbar: '#getType',width: 90}
                ,{field:'loan_status', title:'状态'}
                ,{field:'ip', title:'来源ip'}
                ,{field:'add_time', title:'进来时间'}
                ,{field:'registered_time', title:'注册时间'}
                ,{field:'url', title:'进来地址'}
                ,{field:'address', title:'来源地区'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150 , align: 'center'}
            ]]
            ,page: true
        });
        // 表格重载 用于搜索
        form.on('submit(submit)', function(data){
            var field=data.field;
            if($(data.elem).html()=="重置"){
                $("input").val("");
                field="";
                location.reload();
            }
            table.reload('all', {
                url: '/sign/Show/findData?model=Registered',
                where: {field}
            });
            return false;
        });

        table.on('tool(all)', function(obj){
            var data = obj.data; //获得当前行数据
            var id = obj.data.id
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(obj.event == 'del'){
                layer.confirm('真的删除行么', function(index){
                    layer.close(index);
                    var arr = Array()
                    arr[0] = obj.data
                    var add_time = arr[0]['add_time']
                    //向服务端发送删除指令
                    $.post({
                        url:"/sign/show/delOnePopularize",
                        type:"get",
                        dataType:"json",
                        data:{'model':'Registered',"add_time":add_time},
                        success:function (res) {
                            if(res.code == 404){
                                layer.msg('删除失败！！！请重试');
                            }
                            if(res.code == 200){
                                layer.msg('删除成功！！！');
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            }
                        },
                        error:function (error) {
                            layer.msg('删除失败！！！');
                        }
                    })
                });
            }
        });

        $.ajax({
            url:"/sign/Registered/getStatus",
            type:"get",
            dataType:"json",
            success:function (res) {
                status_d = res.d
                status_f = res.f
                for(var key in status_d){
                    $("#status_d").append("<option value='" + status_d[key] + "'>" + status_d[key] + "</option>");
                }
                for(var key in status_f){
                    $("#status_f").append("<option value='" + status_f[key] + "'>" + status_f[key] + "</option>");
                }
                form.render('select');
            }
        })

        laydate.render({
            elem: '#date' //指定元素
            ,range: '.'
        });

    });
</script>

{/block}